package com.huluobo.a2210mdmdemo.demo

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController

/**
 *  Created by LC on 2025/3/25.
 */

@Composable
fun Demo06() {
    //导航控制器
    val navHostController = rememberNavController()

    //导航器,startDestination 代表首先显示那个页面,builder 声明所有需要用到导航的页面
    NavHost(navController = navHostController, startDestination = "main", builder = {
        composable("main") { MainPage(navHostController = navHostController) }
        composable("sec/{asdas}") {
            val string = it.arguments?.getString("asdas")
            SecondPage(navHostController = navHostController, string!!)
        }
    })
}

@Composable
fun MainPage(navHostController: NavHostController) {
    Text(text = "主页面",
        Modifier
            .fillMaxSize()
            .background(Color.Yellow)
            .clickable {
                //点击跳转
                navHostController.navigate("sec/123")
            })
}

@Composable
fun SecondPage(navHostController: NavHostController, string: String) {
    Text(
        text = "第二页面$string",
        Modifier
            .fillMaxSize()
            .background(Color.Green)
            .clickable {
                navHostController.navigate("main")
            }
    )
}